//
//  InfiniteCollectionView.m
//  RBIOSBase
//
//  Created by ren on 07/12/2017.
//  Copyright © 2017 bryan. All rights reserved.
//

#import "InfiniteCollectionView.h"
#import "TopCollectionReusableView.h"
#import "ImageCollectionViewCell.h"

@interface InfiniteCollectionView ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UICollectionViewFlowLayout *collectionViewLayout;

@end

@implementation InfiniteCollectionView

- (instancetype)initWithFrame:(CGRect)frame
{
	if (self = [super initWithFrame:frame]) {
		_collectionViewLayout = [[UICollectionViewFlowLayout alloc] init];
		[_collectionViewLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
		[_collectionViewLayout setMinimumLineSpacing:0];
		_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) collectionViewLayout:_collectionViewLayout];
		[_collectionView setBackgroundColor:[UIColor redColor]];
		_collectionView.dataSource = self;
		_collectionView.delegate = self;
		
		[_collectionView registerNib:[UINib nibWithNibName:@"ImageCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"ImageCollectionViewCellIdentifier"];
		[_collectionView registerClass:[TopCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"TopCollectionReusableView"];
		[self addSubview:_collectionView];
	}
	return self;
}

#pragma mark - UICollectionViewDataSource

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
	return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
	return 3;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
	ImageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ImageCollectionViewCellIdentifier" forIndexPath:indexPath];
	[cell.imageView setImage:[UIImage imageNamed:@"test"]];
	return cell;
}

#pragma mark - UICollectionViewDelegate

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
	return CGSizeMake(self.bounds.size.width, self.bounds.size.width);
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
	
}

@end
